package com.springboot.sakila.service.impl;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.sakila.entity.Address;
import com.springboot.sakila.mapper.AddressMapper;
import com.springboot.sakila.service.AddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/*
 *DATE:2025/7/14
 */
@Service
@Slf4j
public class AddressServiceImpl implements AddressService {
    @Resource
    private AddressMapper addressMapper;
    @Override
    public Address findById(Integer id) {
        log.debug("findById: {}", id);
        return addressMapper.selectById(id);
    }

    @Override
    public void addOne(Address address) {
        addressMapper.insertOne(address);
    }

    @Override
    public void modOne(Address address) {
        addressMapper.updateOne(address);
    }

    @Override
    public void deleteById(Integer id) {
        log.info("deleteById: {}", id);
        addressMapper.deleteById(id);
    }

    @Override
    public Page<Address> findPage(String address, String phone, int current, int size, String orderBy, boolean asc) {
        Page<Address> page = new Page<>(current, size);
        OrderItem orderItem = new OrderItem();
        page.addOrder(orderItem.setColumn(orderBy).setAsc( asc));
        return addressMapper.selectPage(address, phone, page);
    }

    @Override
    public Page<Address> findAAndCAndtForPages(String address, String phone, int current, int size, String orderBy, boolean asc) {
        Page<Address> page = new Page<>(current, size);
        OrderItem orderItem = new OrderItem();
        page.addOrder(orderItem.setColumn(orderBy).setAsc( asc));
        return addressMapper.selectAAndCAndtForPages(address, phone, page);
    }

}
